<?php 

class Silk_Mapi_Block_Adminhtml_Customerfeedback_Grid extends Mage_Adminhtml_Block_Widget_Grid
{
	public function __construct()
    {
        parent::__construct();
        $this->setId("customerfeedbackGrid");
        $this->setDefaultSort("id");
        $this->setDefaultDir("DESC");
        $this->setSaveParametersInSession(true);
    }

    protected function _prepareCollection()
    {
    	$collection = Mage::getModel("mapi/feedback")->getCollection();
        $this->setCollection($collection);
        return parent::_prepareCollection();
    }

    protected function _prepareColumns()
    {
        $this->addColumn("id", array(
			"header" => Mage::helper("tms")->__("ID"),
			"align" =>"right",
			"width" => "50px",
		    "type" => "number",
			"index" => "id",
		));

		/*$this->addColumn('customer_id', array(
            "header" => Mage::helper("mapi")->__("用户ID"),
            "width" => "50px",
            "index" => "customer_id",
        ));*/

        $this->addColumn('name', array(
            "header" => Mage::helper("mapi")->__("姓名"),
            "width" => "100px",
            "index" => "name",
        ));

        $this->addColumn('mobile', array(
            "header" => Mage::helper("mapi")->__("联系电话"),
            "width" => "100px",
            "index" => "mobile",
        ));

        $this->addColumn('appid', array(
            "header" => Mage::helper("mapi")->__("设备ID"),
            "width" => "100px",
            "index" => "appid",
            'type'  => 'options',
            'options' => Mage::getModel('mapi/feedback')->getDeviceOption(),
        ));

        $this->addColumn('view_count', array(
            "header" => Mage::helper("mapi")->__("查看次数"),
            "width" => "100px",
            "index" => "view_count",
        ));

        $this->addColumn('content', array(
            "header" => Mage::helper("mapi")->__("内容"),
            "width" => "200px",
            "index" => "content",
        ));

        $this->addColumn('created_at', array(
            "header" => Mage::helper("mapi")->__("反馈时间"),
            "width" => "100px",
            "index" => "created_at",
            'type'  => 'datetime'
        ));

        $this->addColumn('website_id', array(
            'header'    => Mage::helper('mapi')->__('Website'),
            'align'     => 'center',
            'width'     => '80px',
            'type'      => 'options',
            'options'   => $this->getWebsite(),
            'index'     => 'website_id',
        ));

        return parent::_prepareColumns();
    }

    public function getRowUrl($row)
    {
        return $this->getUrl("*/*/view", array("id" => $row->getId()));
    }

    protected function getWebsite()
    {
        $websiteId = $this->_getWebsiteId();
        $website = Mage::getModel('core/website')->getCollection()->toOptionHash();
        $outs= array();
        if (key_exists($websiteId,$website))
        {
          $websitename = $website[$websiteId];
          $outs[$websiteId]=$websitename;
          return $outs;

        }
          return $website;
    }

    protected function _getWebsiteId(){
        $websiteId = Mage::getSingleton('admin/session')->getUser()->getWebsiteId();
        return $websiteId;
    }
}